﻿using System;

namespace IOP.Protocols.MQTT.Package
{
    /// <summary>
    /// 断开包
    /// </summary>
    public struct DisconnectPackage : IMQTTPackage
    {

        /// <summary>
        /// 报文类型
        /// </summary>
        public ControlPacketType PacketType { get => ControlPacketType.DISCONNECT; }

        /// <summary>
        /// 剩余大小
        /// </summary>
        public uint RemainingLength { get => 0; }

        /// <summary>
        /// 转换为字节码
        /// </summary>
        /// <returns></returns>
        public Span<byte> ToBytes()
        {
            Span<byte> bytes = stackalloc byte[2];
            Span<byte> result = new byte[2];
            var type = (byte)((byte)PacketType << 4);
            bytes[0] = type;
            bytes[1] = 0;
            bytes.TryCopyTo(result);
            return result;
        }
    }
}
